import { _decorator, Component, instantiate, Label, Node, Prefab, resources, tween, UIOpacity } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('lobby')
export class lobby extends Component {

    @property(Node)
    map: Node = null!;

    @property(Node)
    gui: Node = null!;

    @property(Node)
    toast: Node = null!;

    @property(Node)
    alert: Node = null!;

    static instance: lobby = null!;
    start() {
        lobby.instance = this;
        let prefab = resources.get("prefab/mainui", Prefab)!
        let mianui = instantiate(prefab)
        this.gui.addChild(mianui)
    }
    addUI(path: string) {
        let prefab = resources.get(path, Prefab)!
        let ui = instantiate(prefab)
        lobby.instance.gui.addChild(ui)
        return ui
    }
    showToast(str: string, time = 2) {
        let prefab = resources.get("prefab/toast", Prefab)!
        let toast = instantiate(prefab)
        lobby.instance.toast.getChildByName("Layout")!.addChild(toast);
        toast.getChildByName("Label")!.getComponent(Label)!.string = str;
        tween(toast.getComponent(UIOpacity)!)
            .to(time, { opacity: 0 })
            .call(() => {
                toast.destroy()
            })
            .start()
    }
    update(deltaTime: number) {

    }
}


